package org.example.struct.array2;

import com.alibaba.fastjson.JSON;

/**
 * @author liyishan
 * @date 2023/10/8 10:08
 * @apiNote
 */

public class Test00238ProductExceptSelf {

    public static void main(String[] args) {
        int[] nums = {1,2,3,4};
        int[] result = test(nums);
        System.out.println(JSON.toJSON(result));
    }

    public static int[] test(int[] nums) {
        int[] res = new int[nums.length];
        res[0] = 1;
        for (int i = 1; i < nums.length; i++) {
            res[i] = res[i - 1] * nums[i - 1];
        }
        int right = 1;
        for (int i = nums.length - 1; i >= 0; i--) {
            res[i] *= right;
            right *= nums[i];
        }
        return res;

    }


}
